import React, { Component } from 'react'
import { createRoot } from 'react-dom/client'
class App extends Component {
  state = {
    isShowInput: false,
  }
  inputRef = React.createRef()
  //inputRef = React.createRef()
  render() {
    return (
      <div>
        <h1>我是App组件</h1>
        {this.state.isShowInput === false ? (
          <button onClick={this.handdleClick}>发表评论</button>
        ) : (
          <input type="text" ref={this.inputRef} placeholder="请输入~~~" />
        )}
      </div>
    )
  }
  handdleClick = () => {
    this.setState(
      {
        isShowInput: !this.state.isShowInput,
      },
      () => {
        this.inputRef.current.focus()
      }
    )
  }
}

// 渲染组件
// ReactDOM.render(<App />, document.getElementById('root'))
createRoot(document.querySelector('#root')).render(<App />)
